Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@injectivelabs/grpc-web
Advanced tools
Library for making gRPC-Web requests from a browser
This library is intended for both JavaScript and TypeScript usage from a web browser or NodeJS (see Usage with NodeJS).
Note: This only works if the server supports gRPC-Web
A Golang gRPC-Web middleware and a Golang-based gRPC-Web proxy are available here.
Please see the full gRPC-Web README for known limitations.
@improbable-eng/grpc-web
has peer dependencies of google-protobuf
and @types/google-protobuf
.
npm install google-protobuf @types/google-protobuf @improbable-eng/grpc-web --save
There is an example project available here
ts-protoc-gen
with protoc
to generate .js
and .d.ts
files for your request and response classes. ts-protoc-gen
can also generate gRPC service definitions with the service=true
argument.
unary()
, invoke()
or client()
import {grpc} from "@injectivelabs/grpc-web";
// Import code-generated data structures.
import {BookService} from "./generated/proto/examplecom/library/book_service_pb_service";
import {GetBookRequest} from "./generated/proto/examplecom/library/book_service_pb";
const getBookRequest = new GetBookRequest();
getBookRequest.setIsbn(60929871);
grpc.unary(BookService.GetBook, {
request: getBookRequest,
host: host,
onEnd: res => {
const { status, statusMessage, headers, message, trailers } = res;
if (status === grpc.Code.OK && message) {
console.log("all ok. got book: ", message.toObject());
}
}
});
const request = grpc.unary(BookService.GetBook, { ... });
request.close();
There are three functions for making gRPC requests:
grpc.unary
This is a convenience function for making requests that consist of a single request message and single response message. It can only be used with unary methods.
rpc GetBook(GetBookRequest) returns (Book) {}
grpc.invoke
This is a convenience function for making requests that consist of a single request message and a stream of response messages (server-streaming). It can also be used with unary methods.
rpc GetBook(GetBookRequest) returns (Book) {}
rpc QueryBooks(QueryBooksRequest) returns (stream Book) {}
grpc.client
grpc.client
returns a client. Dependant upon transport compatibility this client is capable of sending multiple request messages (client-streaming) and receiving multiple response messages (server-streaming). It can be used with any type of method, but will enforce limiting the sending of messages for unary methods.
rpc GetBook(GetBookRequest) returns (Book) {}
rpc QueryBooks(QueryBooksRequest) returns (stream Book) {}
rpc LogReadPages(stream PageRead) returns (google.protobuf.Empty) {}
rpc ListenForBooks(stream QueryBooksRequest) returns (stream Book) {}
Refer to grpc-web-node-http-transport.
FAQs
gRPC-Web client for browsers (JS/TS)
The npm package @injectivelabs/grpc-web receives a total of 22,009 weekly downloads. As such, @injectivelabs/grpc-web popularity was classified as popular.
We found that @injectivelabs/grpc-web demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.